export interface Set<T>{
    add(t:T);
    remove(t:T);
    indexOf(t:T):number;
    size():number;
    clear();
    toArray():T[];
}

export class ArraySet<T> implements Set<T> {
    private arr:Array<T>=[];
    add(t: T) {
        this.indexOf(t)<0&&this.arr.push(t);
    }
    remove(t: T) {
        let i=this.indexOf(t);
        if(i>=0){
            delete this.arr[i];
        }
    }
    indexOf(t: T): number {
        return this.arr.indexOf(t);
    }
    size(): number {
        return Object.keys(this.arr).length;
    }
    clear() {
        delete this.arr;
        this.arr=[];
    }
    toArray(): T[] {
        let arr=new Array<T>();
        for(let i=0;i<this.arr.length;i++){
            this.arr[i]&&arr.push(this.arr[i]);
        }
        return arr;
    }
}